<meta name="viewpoint" content="width=device-width,initial-scale=1.0" charset="UTF-8">
<link href="../css/bootstrap.min.css" rel="stylesheet"/>
<link href="../css/bootstrap-table.min.css" rel="stylesheet"/>
<link href="../css/main.css" rel="stylesheet"/>
<script src="../js/jquery-1.9.1.js"></script>
<div class="container" id="confirm" >
	<div class="row" >
		<div class="col-md-3"></div>
		<div class="col-md-6">
			<h3 class="text-danger text-center">核对密码</h3>
			<form class="form-horizontal">
				<div class="form-group">
				</div>
				<div class="form-group">
					<label for="spwd" class="col-md-2 control-label"></label>
					<div class="col-md-10">
						<input type="password" class="form-control input-lg" id="currPwd" placeholder="请输入密码">
					</div>
				</div>
				<div class="form-group">
					<div class="col-md-8 col-md-offset-2">
						<div id="reminder1"></div>
						<button type="button" id="confirmBtn" class="btn btn-danger btn-lg btn-block"><span class="glyphicon glyphicon-ok"></span></button>
					</div>
				</div>
			</form>
		</div>
		<div class="col-md-3"></div>
	</div>
</div>
<div class="container" id="modify" style="display:none">
	<div class="row">
		<div class="col-md-3"></div>
		<div class="col-md-6">
			<h3 class="text-danger text-center">修改密码</h3>
			<form class="form-horizontal">
				<div class="form-group">
				</div>
				<div class="form-group">
					<label for="spwd" class="col-md-2 control-label"></label>
					<div class="col-md-10">
						<input type="password" class="form-control input-lg" id="newPwd" placeholder="请输入新的密码">
					</div>
				</div>
				<div class="form-group">
					<label for="spwd" class="col-md-2 control-label"></label>
					<div class="col-md-10">
						<input type="password" class="form-control input-lg" id="confirmPwd" placeholder="请再次输入密码">
					</div>
				</div>
				<div class="form-group">
					<div class="col-md-8 col-md-offset-2">
						<div id="reminder2"></div>
						<button type="button" id="modifyBtn" class="btn btn-danger btn-lg btn-block"><span class="glyphicon glyphicon-ok"></span></button>
					</div>
				</div>
			</form>
		</div>
		<div class="col-md-3"></div>
	</div>
</div>
<script src="../js/bootstrap.min.js"></script>
<script src="../js/bootstrap-table.min.js"></script>
<script src="../js/bootstrap-table-zh-CN.min.js"></script>
<script src="../js/ajaxfileupload.js"></script>
<script>
$(function(){
	$("#confirmBtn").click(function(){
		var currPwd = $("#currPwd").val();
		if(currPwd==""){
			$("#reminder1").html("<div class='alert alert-warning'><span class='glyphicon glyphicon-alert'></span>&nbsp;密码不能为空!</div>");
			$("#currPwd").focus();
			return;
		}
		$.ajax({
			url: "/login.action",
			type: "POST",
			dataType: "JSON",
			data: "spwd="+currPwd+"&op=stuCheck",
			success: function(data){
				if(data>0){//密码正确
					$("#reminder1").html("<div class='alert alert-success'><span class='glyphicon glyphicon-alert'></span>&nbsp;密码正确!</div>");
					window.setTimeout(function(){
						$("#confirm").css("display","none");
						$("#modify").css("display","block");
						
					},1000);
				}else if(data<=0){
					$("#reminder1").html("<div class='alert alert-danger'><span class='glyphicon glyphicon-alert'></span>&nbsp;密码错误!</div>");
					$("#currPwd").val("");		
				}
			}
		});
	});
	$("#modifyBtn").click(function(){
		var newPwd = $("#newPwd").val();
		var confirmPwd = $("#confirmPwd").val();
		if(newPwd=="" || confirmPwd==""){//不能为空
			$("#reminder2").html("<div class='alert alert-warning'><span class='glyphicon glyphicon-alert'></span>&nbsp;密码不能为空!</div>");
			if(newPwd==""){
				$("#newPwd").focus();
			}else if(confirmPwd==""){
				$("#confirmPwd").focus();
			}
			return;
		}
		if(newPwd != confirmPwd){//两次输入 的密码不一致
			$("#reminder2").html("<div class='alert alert-warning'><span class='glyphicon glyphicon-alert'></span>&nbsp;两次密码输入不一致!</div>");
			$("#confirmPwd").val("");
			return;
		}
		console.log("新密码："+confirmPwd);
		$.ajax({
			url: "/login.action",
			type: "POST",
			dataType: "JSON",
			data: "spwd="+confirmPwd+"&op=stuModify",
			success: function(data){
				if(data>=1){//密码正确
					$("#reminder2").html("<div class='alert alert-success'><span class='glyphicon glyphicon-alert'></span>&nbsp;密码修改成功!</div>");
					window.setTimeout(function(){
						location.reload();
					},3000);
				}else if(data<=0){
					$("#reminder2").html("<div class='alert alert-danger'><span class='glyphicon glyphicon-alert'></span>&nbsp;密码错误!</div>");
				}
			}
		});		
	});
})
</script>